<?php

namespace app\uniapp\service;

use app\model\site\Article;
use app\uniapp\service\traits\InstanceTrait;
use think\db\Query;

class ArticleService extends UniBaseService
{

    use InstanceTrait;

    function initialize()
    {
        $this->model = new Article();
    }

    function formatData(array $data): array
    {
        return $data;
    }

    function query(): Query
    {
        return $this->makeQuery()
            ->where('is_show', 1)
            ->where('status',1)
            ->order('create_time desc')
            ->filter(function ($v) {
                $domain = request()->domain();
                $v->content = preg_replace('/(<img.+?src=")(\/uploads)/','$1'.$domain.'$2', $v->content);
            });
    }
}
